/*package com.zhd.service;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map;

import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.client.producer.SendStatus;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Service;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.zhd.entity.PptnDataVO;

@Service
public class PptnService {
	private static final Logger logger = LoggerFactory.getLogger(PptnService.class);
	
	@Autowired
    private ObjectMapper objectMapper;
	@Autowired
    private RocketMQTemplate rocketMQTemplate;
	@Autowired
    @Qualifier("vcTemplate")
	private JdbcTemplate vcTemplate;
	
	DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
	
	public void rainSchedule() throws JsonProcessingException {
		LocalDateTime now = LocalDateTime.now().minusMinutes(60).withSecond(0);
		
		String sql = "select STCD sn, TM time, DRP drp "
				+ "from ST_PPTN_R "
				+ "WHERE TM >= ? "
				+ "and INTV = 0.05";
		
		List<PptnDataVO> list = vcTemplate.query(sql, new BeanPropertyRowMapper<PptnDataVO>(PptnDataVO.class), dtf.format(now));
		
		// 一条数据为一个采集器加上传感器的数据
		Map<String, Object> deviceMap = null;
		for(PptnDataVO vo : list) {
			// 组装传感器数据
			List<Map<String, Object>> data = Lists.newArrayList();
			Map<String, Object> dataMap = Maps.newHashMap();
			dataMap.put("id", "drp");
			dataMap.put("key", "drp");
			dataMap.put("val", vo.getDrp());
			data.add(dataMap);
			
			// 组装采集器数据
			deviceMap = Maps.newHashMap();
			deviceMap.put("devId", vo.getSn());
			deviceMap.put("sn", vo.getSn());
			deviceMap.put("time", dtf.format(vo.getTime()));
			deviceMap.put("tenantId", "");
			deviceMap.put("tags", null);
			deviceMap.put("data", data);
			
			String message = objectMapper.writeValueAsString(deviceMap);
			
			rocketMQTemplate.asyncSend("iot-huacheng:" + vo.getSn(), MessageBuilder.withPayload(message).setHeader("KEYS", vo.getSn()).build(), new SendCallback() {
				@Override
                public void onSuccess(SendResult result) {
                    if (result.getSendStatus() == SendStatus.SEND_OK) {
                        logger.info("vc雨量数据转发成功={}", message);
                    }
                }
                @Override
                public void onException(Throwable e) {
                    logger.error("vc雨量数据转发失败={}", e.getMessage());
                }
            });
		}
	}
}*/